package edu.luc.concordia;

/**
 * Copyright 2008 Project Concordia
 * <p>
 * This file is part of RetailReturnSystem.
 * <p>
 * RetailReturnSystem is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * <p>
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * <p>
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <a href="http://www.gnu.org/licenses/">http://www.gnu.org/licenses/</a>.
 * <hr>
 * SE project 
 * Inventory class
 * @author Yumin Li 
 * @version 1
 */

import java.util.ArrayList;
import java.util.HashMap;
 

public class Inventory

{

    //A collection of all Products in the system. Keys (primary) are the UID of the Product. Values are the individual Product objects. 

	private HashMap< String, Product > myDatabase ;
    private HashMap<String, PriceScheme> mySchemes;
	private HashMap<String, String> myMemberInfo; 
    private int myTaxRate;
    private HashMap<String, ArrayList<String>> myCategoryInfo; // key = category ID, value = array [description, price scheme 1 ID, price scheme2 ID, etc]

    /**

     Constructor 

     */

    public Inventory()

    {

        //Initializes myDatabase as an empty HashMap< String, Product >

        myDatabase = new HashMap< String, Product >();
        mySchemes = new HashMap<String, PriceScheme>();
        myMemberInfo = new HashMap<String, String>();
        myTaxRate = 0;
        myCategoryInfo = new HashMap<String, ArrayList<String>>();

    }
    

    public boolean addProduct( Product prod )
    {  

        /**checks to see if the product is already in the database

          Adds the Product to the HashMap with the Product UID as the key 

          Returns True if the Product was add successfully. False otherwise.

         */

         

    	if ( !myDatabase.containsKey( prod.getUID() ) )   

            {

                //prod is the Product to be added to the Inventory

                myDatabase.put( prod.getUID(), prod );

                return true;

            }   

       return false;

     }

        

     public Product getProduct( String uid )   

     {

       // uid is the key to search with     

       return myDatabase.get( uid );

     }    
     
     public synchronized int getTaxRate()
     {
 		return myTaxRate;
     }


     public synchronized void setTaxRate(int taxRate)
     {
 		this.myTaxRate = taxRate;
     }
     
     public boolean addPriceScheme(PriceScheme ps)
     {
    	 if (!mySchemes.containsKey(ps.getID()))
    	 {
    		 mySchemes.put(ps.getID(), ps);
    		 return true;
    	 }
    	 return false;
     }
     
     public PriceScheme getPriceScheme(String id)
     {
    	return mySchemes.get(id); 
     }
     
     public void removePriceScheme(String id)
     {
    	 mySchemes.remove(id);
     }
     
     public boolean addMemberInfo(String id, String info)
     {
    	 if(!myMemberInfo.containsKey(id))
    	 {
    		 myMemberInfo.put(id, info);
    		 return true;
    	 }
    	 return false;
     }
     
     public String getMemberInfo(String id)
     {
    	 return myMemberInfo.get(id);
     }
     
     public void removeMemberInfo(String id)
     {
    	 myMemberInfo.remove(id);
     }
     
     public boolean addCategory(String id, ArrayList<String> info)
     {
    	 if(!myCategoryInfo.containsKey(id))
    	 {
    		 myCategoryInfo.put(id, info);
    		 return true;
    	 }
    	 return false;
     }
     
     public ArrayList<String> getCategory(String id)
     {
    	 return myCategoryInfo.get(id);
     }
     
     public void removeCategory(String id)
     {
    	 myCategoryInfo.remove(id);
     }

}

